<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/3/3
  Time: 17:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="static/css/public.css" />
    <style type="text/css">
        *{
            padding: 0;
            margin: 0;
        }
        ul li{
            list-style: none;
        }
        /*body{
            width: 980px;
            margin: 0 auto;
        }*/
        #nav ul li{
            float: left;
        }
        #rootShow ul li{
            float: left;
            margin-right: 50px;
        }
        #rootShow .item, #rootShow img{
            width: 250px;
            height: 150px;
        }
        #rootShow .item{
            width: 250px;
            height: 180px;
        }
        #rootShow p{
            text-align: center;
            line-height: 30px;
        }
        p,tr{
            line-height: 30px;
        }
        /*p{
            text-indent: 30px;
        }*/

    </style>
    <script type="text/javascript" src="static/qui/libs/js/jquery.js"></script>
    <script type="text/javascript" src="static/js/jquery.form.js"></script>
</head>
<body>
<jsp:include page="head.jsp"></jsp:include>

<div id="main">
    <div style="margin-left: 100px;margin-bottom: 20px;">
        <h2 style="text-align: center">2019新生寝室大赛</h2>
        <p id="raceContent" style="margin-top: 20px;margin-bottom: 20px;">赛事内容 ：全体2019新生</p>
        <p style="text-align: center;margin-bottom: 20px;"><img src="static/images/ad.jpg"> </p>
        <p id="time">比赛时间 ：2019年4月12日-2019年4月13日</p>
        <p ><span style="font-weight: bold;">活动对象 ：</span>广西师范大学育才校区职师学院全体新生寝室</p>
        <p ><span style="font-weight: bold;">活动地点：</span>广西师范大学育才校区各公寓区</p>
        <p ><span style="font-weight: bold;">活动单位：</span></span>职业技术师范学院</p>
        <p><span style="visibility:hidden">隐藏</span><span style="font-weight: bold;">附件：</span><a id="fileDownload" href="#">赛事规则说明下载</a></p>
        <br>
        <div style="display: none" id="noLogin">登录后方可参加比赛,<a onclick="goLogin()" href="javascipt:;">现在就登录</a></div>
        <div id="isLogin" style="display: none;">
            <p>参加比赛：</p>
            <form id="formData">
            <table>
                <tr>
                    <td>请核对你的报名信息：</td>
                    <td>
                       宿舍号：<span id="dormNo"></span>
                        <input  title="宿舍号" id="roomNumber" name="roomNumber" type="hidden" />
                    </td>
                </tr>
                <tr>
                    <td>上传宿舍图片:</td>
                    <td><input  name="roomImg" type="file" accept=".jpg">* 请上传jpg文件</td>
                </tr>
            </table>
                <%--<div style="background: #2DA9FA;height: 30px;width: 120px;">报名</div>--%>
                <br>
            <button style="height: 30px;width: 80px;margin-left: 200px;" type="button" onclick="submitHandler()">报名</button>
        </div>
        </form>
    </div>
</div>
<p id="no" style="text-align: center;display:none;">当前没有比赛！</p>
<script type="text/javascript" src="static/js/common.js"></script>
<script src="http://ptce.gx12333.net/common/artDialog/jquery.artDialog.js?skin=blue"></script>
<script type="text/javascript">
    if(userInfo==null){
        $("#noLogin").show();
    }
    else{
        $("#dormNo").text(userInfo.dormNo);
        $("#roomNumber").val(userInfo.dormNo);
        $("#isLogin").show();
    }

    function goLogin() {
            var dialog = art.dialog({id: 'N3690',title: false});
            $.ajax({
                url: './studentLogin.jsp',
                success: function (data) {
                    dialog.content(data);
                },
                cache: false
            });
    }
    
    $.getJSON("thisRace/getAllData",function (data) {
        if(data.length>0){
            $("#main h2").text(data[0].title);
            $("#raceContent").text(""+data[0].raceContent);
            $("#time").html('<span style="font-weight: bold;">比赛时间：</span>'+data[0].beginTime+'至'+data[0].endTime);
            $("#fileDownload").attr("href","/upload"+data[0].filePath);
        }
        else{
            $("#main").hide();
            $("#no").show();
        }
    });

    function submitHandler() {
        if($("#roomNumber").val()===""){
            alert("无法取得宿舍号!");
            return;
        }
        var fromData = new FormData(document.getElementById("formData"));
        $.ajax({
            url:"/rootManage/add",
            type:"post",
            data:fromData,
            processData:false,
            contentType:false,
            success:function(data){
                if(data.success){
                    alert("报名成功，请等待管理员审核！");
                    /* top.Toast('showSuccessToast', data.msg);
                     //刷新数据
                     top.frmright.refresh();
                     //关闭窗口
                     top.Dialog.close();*/
                    window.location.href="/";
                }
                else{
                    alert("请上传宿舍照片！");
                    /*top.Toast('showWarningToast', data.msg);*/
                }
            },
            error:function(e){
                alert("报名失败请上传宿舍照片！");
            }
        });
    }
    $("#nav ul li").click(function(){
        /*当前标签下的a标签*/
        var obj = $(this).children("a");
        /*获取第一个a标签，进行跳转*/
        window.location.href=$(obj[0]).attr("href");
    });
</script>
</body>
</html>
